package uk.ac.glasgow.demosocs.impl.ui;

import java.util.Set;

import uk.ac.glasgow.clui.CommandDescription;
import uk.ac.glasgow.clui.MinimumArguments;
import uk.ac.glasgow.clui.SystemCommand;
import uk.ac.glasgow.clui.SystemCommandException;
import uk.ac.glasgow.demosocs.Election;
import uk.ac.glasgow.demosocs.VotingSystem;
import uk.ac.glasgow.demosocs.impl.ElectionImpl;

@MinimumArguments(0)
@CommandDescription("List all elections.")
public class GetElectionsCommand extends SystemCommand<VotingSystem> {

	public GetElectionsCommand(VotingSystem facade) {
		super(facade);
	}

	@Override
	public String processCommand(String[] arguments) throws SystemCommandException {

		String guid = facade.getCurrentUserGUID();
		if (guid == null)
			throw new SystemCommandException("No current user set.");

		String result = String.format("%s\t%-20s %-12s %-30s %-30s %-30s \n", "EID", "Election Type", "State", "Nominations Open", "Starting", "Ending"); // "EID Election Type Stat Nominations Open Starting Ending\n".for;

		Set<Election> elections = facade.getElections();

		for (Election election : elections) {
			result += String.format("%s\t%-20s %-12s %-30s %-30s %-30s \n", election.getEID(),
					((ElectionImpl) election).getElectionType(), 
					election.getElectionState(), election.getOpenNominations(), election.getStart(),
					election.getEnd());

		}
		return result;
	}

}
